<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>08_正则验证0~255</title>
  </head>

  <body>
    <input type="text" id="ip" />
    <button id="btn">测试</button>

    <script>
      const btn = document.getElementById("btn");

      btn.addEventListener(
        "click",

        (e) => {
          let reg = /^((\d)|([1-9]\d)|(1\d{2})|(2[0-4]\d)|(25[0-5]))$/;

          let ok = reg.test(ip.value);
          alert(ok ? "是合法的颜色通道" : "不是合法的颜色通道");
        }
      );
    </script>
  </body>
</html>
